package com.bitter.order.controller;

import java.util.Random;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.bitter.order.domain.OrderVo;
import com.bitter.order.service.IOrderService;

/**
 * 订单管理
 * 
 * @author thomashe
 *
 */
@RestController
@RequestMapping("/order")
public class OrderController {

	private Logger log = LoggerFactory.getLogger(OrderController.class);

	@Autowired
	private IOrderService iOrderService;

	/**
	 * 下单
	 * 
	 * @param productId
	 * @param total
	 * @return
	 */
	@RequestMapping("/create")
	public String create(@RequestParam("productId") Long productId, @RequestParam("total") Integer total) {
		log.info("###########进入下单#########，参数productId:{},total:{}", productId, total);
		OrderVo orderVo = new OrderVo();
		orderVo.setId(new Random().nextInt(100));
		orderVo.setProduct_id(productId);
		orderVo.setTotal(total);// 数据
		iOrderService.create(orderVo);
		return "successfully.";
	}

	
	@RequestMapping("/test")
	public String test() {
		return "hello OrderController.";
	}
}
